package com.pan.admin.module.loanConfig.controller;

import com.pan.admin.common.annotation.Log;
import com.pan.admin.common.core.controller.BaseController;
import com.pan.admin.common.core.domain.AjaxResult;
import com.pan.admin.common.core.page.TableDataInfo;
import com.pan.admin.common.enums.BusinessType;
import com.pan.admin.common.utils.poi.ExcelUtil;
import com.pan.admin.module.loanConfig.entity.LoanRegisterField;
import com.pan.admin.module.loanConfig.service.LoanRegisterFieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 注册要素字段配置Controller
 *
 * @author ts
 * @date 2023-09-08
 */
@RestController
@RequestMapping("/loanUser/field")
public class LoanRegisterFieldController extends BaseController {

    @Autowired
    private LoanRegisterFieldService loanRegisterFieldService;

    /**
     * 查询注册要素字段配置列表
     */
    @PreAuthorize("@ss.hasPermi('loanUser:field:list')")
    @GetMapping("/list")
    public TableDataInfo list(LoanRegisterField loanRegisterField) {
        startPage();
        List<LoanRegisterField> list = loanRegisterFieldService.selectLoanRegisterFieldList(loanRegisterField);
        return getDataTable(list);
    }

    /**
     * 导出注册要素字段配置列表
     */
    @PreAuthorize("@ss.hasPermi('loanUser:field:export')")
    @Log(title = "注册字段配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LoanRegisterField loanRegisterField) {
        List<LoanRegisterField> list = loanRegisterFieldService.selectLoanRegisterFieldList(loanRegisterField);
        ExcelUtil<LoanRegisterField> util = new ExcelUtil<LoanRegisterField>(LoanRegisterField.class);
        util.exportExcel(response, list, "注册要素字段配置数据");
    }

    /**
     * 获取注册要素字段配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('loanUser:field:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(loanRegisterFieldService.selectLoanRegisterFieldById(id));
    }

    /**
     * 新增注册要素字段配置
     */
    @PreAuthorize("@ss.hasPermi('loanUser:field:add')")
    @Log(title = "注册字段配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LoanRegisterField loanRegisterField) {
        return toAjax(loanRegisterFieldService.insertLoanRegisterField(loanRegisterField));
    }

    /**
     * 修改注册要素字段配置
     */
    @PreAuthorize("@ss.hasPermi('loanUser:field:edit')")
    @Log(title = "注册字段配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LoanRegisterField loanRegisterField) {
        return toAjax(loanRegisterFieldService.updateLoanRegisterField(loanRegisterField));
    }

}
